package com.mooc.ppjoke.utils;

import java.util.Calendar;

/**
 * @ClassName: TimeUtils$
 * @Description: java类作用描述
 * @Author: 魏靳元
 * @CreateDate: 2022/8/25 09:04
 * @UpdateRemark: 更新内容
 * @Version: 1.0
 */
public class TimeUtils {
    public static String calculate(long time){
        long timeInMillis= Calendar.getInstance().getTimeInMillis();
        long diff=(timeInMillis-time)/1000;
        if(diff<60){
            return diff+"秒前";
        }else if(diff<3600){
            return diff / 60 + "分钟前";
        }else if(diff<3600*24){
            return diff/3600+"小时前";
        }else {
            return diff / (3600 * 24) + "天前";
        }
    }
} 
